using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using C1.Win.C1Input;
using C1.Win.C1TrueDBGrid;
using PCSComProduction.WorkOrder.BO;
using PCSComProduction.WorkOrder.DS;
using PCSComUtils.Admin.DS;
using PCSComUtils.Common;
using PCSComUtils.Common.BO;
using PCSComUtils.Framework.ReportFrame.BO;
using PCSComUtils.PCSExc;
using PCSUtils.Framework.ReportFrame;
using PCSUtils.Log;
using PCSUtils.Utils;
using CancelEventArgs = System.ComponentModel.CancelEventArgs;
using PCSComUtils.DataContext;

namespace PCSProduction.WorkOrder
{
    /// <summary>
    /// Summary description for MultiWOCompletion.
    /// </summary>
    public class MultiWOCompletion : Form
    {
        protected const string THIS = "PCSProduction.WorkOrder.MultiWOCompletion";
        private TextBox txtFGoodsCode;
        private TextBox txtMasLoc;
        private Label lblFGoodsCode;
        private Button btnFGoodsCode;
        private C1DateEdit dtmPostDate;
        private Button btnSearchMasLoc;
        private Label lblMasLoc;
        private Label lblPostDate;
        private TextBox txtProductionLine;
        private Label lblProductionLine;
        private Button btnProductionLine;
        private Button btnworkcenter;
        private TextBox txtWorkcenter;
        private Label lblWorkCenter;
        private Button btnClose;
        private Button btnHelp;
        private CheckBox chkSelectAll;
        private Button btnPrintBOMShortage;
        private Button btnSave;
        private Label lblLocation;
        private TextBox txtLocation;
        private Button btnSearchLocation;
        int intSelectedRow = 0;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private Container components = null;

        DataSet dstData = new DataSet();
        DataTable dtbGridLayout = new DataTable();
        WorkOrderCompletionBO boWOCompletion = new WorkOrderCompletionBO();
        private C1.Win.C1TrueDBGrid.C1TrueDBGrid dgrdData;
        private bool blnStateOfCheck = false;

        public MultiWOCompletion()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MultiWOCompletion));
            C1.Win.C1TrueDBGrid.Style style1 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style2 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style3 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style4 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style5 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style6 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style7 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style8 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style9 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style10 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style11 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style12 = new C1.Win.C1TrueDBGrid.Style();
            C1.Win.C1TrueDBGrid.Style style13 = new C1.Win.C1TrueDBGrid.Style();
            this.txtFGoodsCode = new System.Windows.Forms.TextBox();
            this.txtMasLoc = new System.Windows.Forms.TextBox();
            this.lblFGoodsCode = new System.Windows.Forms.Label();
            this.btnFGoodsCode = new System.Windows.Forms.Button();
            this.dtmPostDate = new C1.Win.C1Input.C1DateEdit();
            this.btnSearchMasLoc = new System.Windows.Forms.Button();
            this.lblMasLoc = new System.Windows.Forms.Label();
            this.lblPostDate = new System.Windows.Forms.Label();
            this.txtProductionLine = new System.Windows.Forms.TextBox();
            this.lblProductionLine = new System.Windows.Forms.Label();
            this.btnProductionLine = new System.Windows.Forms.Button();
            this.btnworkcenter = new System.Windows.Forms.Button();
            this.txtWorkcenter = new System.Windows.Forms.TextBox();
            this.lblWorkCenter = new System.Windows.Forms.Label();
            this.btnClose = new System.Windows.Forms.Button();
            this.btnHelp = new System.Windows.Forms.Button();
            this.btnSave = new System.Windows.Forms.Button();
            this.chkSelectAll = new System.Windows.Forms.CheckBox();
            this.btnPrintBOMShortage = new System.Windows.Forms.Button();
            this.lblLocation = new System.Windows.Forms.Label();
            this.txtLocation = new System.Windows.Forms.TextBox();
            this.btnSearchLocation = new System.Windows.Forms.Button();
            this.dgrdData = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
            ((System.ComponentModel.ISupportInitialize)(this.dtmPostDate)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgrdData)).BeginInit();
            this.SuspendLayout();
            // 
            // txtFGoodsCode
            // 
            this.txtFGoodsCode.AccessibleDescription = null;
            this.txtFGoodsCode.AccessibleName = null;
            resources.ApplyResources(this.txtFGoodsCode, "txtFGoodsCode");
            this.txtFGoodsCode.BackgroundImage = null;
            this.txtFGoodsCode.Font = null;
            this.txtFGoodsCode.Name = "txtFGoodsCode";
            this.txtFGoodsCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtFGoodsCode_KeyDown);
            this.txtFGoodsCode.Validating += new System.ComponentModel.CancelEventHandler(this.txtFGoodsCode_Validating);
            // 
            // txtMasLoc
            // 
            this.txtMasLoc.AccessibleDescription = null;
            this.txtMasLoc.AccessibleName = null;
            resources.ApplyResources(this.txtMasLoc, "txtMasLoc");
            this.txtMasLoc.BackgroundImage = null;
            this.txtMasLoc.Font = null;
            this.txtMasLoc.Name = "txtMasLoc";
            this.txtMasLoc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMasLoc_KeyDown);
            this.txtMasLoc.Validating += new System.ComponentModel.CancelEventHandler(this.txtMasLoc_Validating);
            // 
            // lblFGoodsCode
            // 
            this.lblFGoodsCode.AccessibleDescription = null;
            this.lblFGoodsCode.AccessibleName = null;
            resources.ApplyResources(this.lblFGoodsCode, "lblFGoodsCode");
            this.lblFGoodsCode.Font = null;
            this.lblFGoodsCode.ForeColor = System.Drawing.Color.Maroon;
            this.lblFGoodsCode.Name = "lblFGoodsCode";
            // 
            // btnFGoodsCode
            // 
            this.btnFGoodsCode.AccessibleDescription = null;
            this.btnFGoodsCode.AccessibleName = null;
            resources.ApplyResources(this.btnFGoodsCode, "btnFGoodsCode");
            this.btnFGoodsCode.BackgroundImage = null;
            this.btnFGoodsCode.Font = null;
            this.btnFGoodsCode.Name = "btnFGoodsCode";
            this.btnFGoodsCode.Click += new System.EventHandler(this.btnFGoodsCode_Click);
            // 
            // dtmPostDate
            // 
            resources.ApplyResources(this.dtmPostDate, "dtmPostDate");
            this.dtmPostDate.AccessibleDescription = null;
            this.dtmPostDate.AccessibleName = null;
            this.dtmPostDate.BackgroundImage = null;
            // 
            // 
            // 
            this.dtmPostDate.Calendar.AccessibleDescription = null;
            this.dtmPostDate.Calendar.AccessibleName = null;
            this.dtmPostDate.Calendar.BackgroundImage = null;
            this.dtmPostDate.Calendar.BackgroundImageLayout = ((System.Windows.Forms.ImageLayout)(resources.GetObject("dtmPostDate.Calendar.BackgroundImageLayout")));
            this.dtmPostDate.Calendar.FirstDayOfWeek = ((System.Windows.Forms.Day)(resources.GetObject("dtmPostDate.Calendar.FirstDayOfWeek")));
            this.dtmPostDate.Calendar.Font = null;
            this.dtmPostDate.Calendar.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("dtmPostDate.Calendar.ImeMode")));
            this.dtmPostDate.Calendar.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("dtmPostDate.Calendar.RightToLeft")));
            this.dtmPostDate.Calendar.RightToLeftLayout = ((bool)(resources.GetObject("dtmPostDate.Calendar.RightToLeftLayout")));
            this.dtmPostDate.Calendar.ShowClearButton = ((bool)(resources.GetObject("dtmPostDate.Calendar.ShowClearButton")));
            this.dtmPostDate.Calendar.ShowTodayButton = ((bool)(resources.GetObject("dtmPostDate.Calendar.ShowTodayButton")));
            this.dtmPostDate.Calendar.ShowWeekNumbers = ((bool)(resources.GetObject("dtmPostDate.Calendar.ShowWeekNumbers")));
            this.dtmPostDate.DisplayFormat.Inherit = ((C1.Win.C1Input.FormatInfoInheritFlags)(resources.GetObject("dtmPostDate.DisplayFormat.Inherit")));
            this.dtmPostDate.EditFormat.Inherit = ((C1.Win.C1Input.FormatInfoInheritFlags)(resources.GetObject("dtmPostDate.EditFormat.Inherit")));
            this.dtmPostDate.EditMask = null;
            this.dtmPostDate.ErrorInfo.BeepOnError = ((bool)(resources.GetObject("dtmPostDate.ErrorInfo.BeepOnError")));
            this.dtmPostDate.ErrorInfo.ErrorMessage = resources.GetString("dtmPostDate.ErrorInfo.ErrorMessage");
            this.dtmPostDate.ErrorInfo.ErrorMessageCaption = resources.GetString("dtmPostDate.ErrorInfo.ErrorMessageCaption");
            this.dtmPostDate.ErrorInfo.ShowErrorMessage = ((bool)(resources.GetObject("dtmPostDate.ErrorInfo.ShowErrorMessage")));
            this.dtmPostDate.Font = null;
            this.dtmPostDate.MaskInfo.AutoTabWhenFilled = ((bool)(resources.GetObject("dtmPostDate.MaskInfo.AutoTabWhenFilled")));
            this.dtmPostDate.MaskInfo.Inherit = ((C1.Win.C1Input.MaskInfoInheritFlags)(resources.GetObject("dtmPostDate.MaskInfo.Inherit")));
            this.dtmPostDate.MaskInfo.PromptChar = ((char)(resources.GetObject("dtmPostDate.MaskInfo.PromptChar")));
            this.dtmPostDate.MaskInfo.ShowLiterals = ((C1.Win.C1Input.ShowLiteralsEnum)(resources.GetObject("dtmPostDate.MaskInfo.ShowLiterals")));
            this.dtmPostDate.MaskInfo.StoredEmptyChar = ((char)(resources.GetObject("dtmPostDate.MaskInfo.StoredEmptyChar")));
            this.dtmPostDate.Name = "dtmPostDate";
            this.dtmPostDate.ParseInfo.DateTimeStyle = ((C1.Win.C1Input.DateTimeStyleFlags)(resources.GetObject("dtmPostDate.ParseInfo.DateTimeStyle")));
            this.dtmPostDate.ParseInfo.Inherit = ((C1.Win.C1Input.ParseInfoInheritFlags)(resources.GetObject("dtmPostDate.ParseInfo.Inherit")));
            this.dtmPostDate.PostValidation.Inherit = ((C1.Win.C1Input.PostValidationInheritFlags)(resources.GetObject("dtmPostDate.PostValidation.Inherit")));
            this.dtmPostDate.PostValidation.Validation = ((C1.Win.C1Input.PostValidationTypeEnum)(resources.GetObject("dtmPostDate.PostValidation.Validation")));
            this.dtmPostDate.PreValidation.Inherit = ((C1.Win.C1Input.PreValidationInheritFlags)(resources.GetObject("dtmPostDate.PreValidation.Inherit")));
            this.dtmPostDate.PreValidation.ItemSeparator = resources.GetString("dtmPostDate.PreValidation.ItemSeparator");
            this.dtmPostDate.PreValidation.PatternString = resources.GetString("dtmPostDate.PreValidation.PatternString");
            this.dtmPostDate.PreValidation.RegexOptions = ((C1.Win.C1Input.RegexOptionFlags)(resources.GetObject("dtmPostDate.PreValidation.RegexOptions")));
            this.dtmPostDate.PreValidation.Validation = ((C1.Win.C1Input.PreValidationTypeEnum)(resources.GetObject("dtmPostDate.PreValidation.Validation")));
            this.dtmPostDate.Tag = null;
            // 
            // btnSearchMasLoc
            // 
            this.btnSearchMasLoc.AccessibleDescription = null;
            this.btnSearchMasLoc.AccessibleName = null;
            resources.ApplyResources(this.btnSearchMasLoc, "btnSearchMasLoc");
            this.btnSearchMasLoc.BackgroundImage = null;
            this.btnSearchMasLoc.Font = null;
            this.btnSearchMasLoc.Name = "btnSearchMasLoc";
            this.btnSearchMasLoc.Click += new System.EventHandler(this.btnSearchMasLoc_Click);
            // 
            // lblMasLoc
            // 
            this.lblMasLoc.AccessibleDescription = null;
            this.lblMasLoc.AccessibleName = null;
            resources.ApplyResources(this.lblMasLoc, "lblMasLoc");
            this.lblMasLoc.Font = null;
            this.lblMasLoc.ForeColor = System.Drawing.Color.Maroon;
            this.lblMasLoc.Name = "lblMasLoc";
            // 
            // lblPostDate
            // 
            this.lblPostDate.AccessibleDescription = null;
            this.lblPostDate.AccessibleName = null;
            resources.ApplyResources(this.lblPostDate, "lblPostDate");
            this.lblPostDate.Font = null;
            this.lblPostDate.ForeColor = System.Drawing.Color.Maroon;
            this.lblPostDate.Name = "lblPostDate";
            // 
            // txtProductionLine
            // 
            this.txtProductionLine.AccessibleDescription = null;
            this.txtProductionLine.AccessibleName = null;
            resources.ApplyResources(this.txtProductionLine, "txtProductionLine");
            this.txtProductionLine.BackgroundImage = null;
            this.txtProductionLine.Font = null;
            this.txtProductionLine.Name = "txtProductionLine";
            this.txtProductionLine.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtProductionLine_KeyDown);
            this.txtProductionLine.Validating += new System.ComponentModel.CancelEventHandler(this.txtProductionLine_Validating);
            // 
            // lblProductionLine
            // 
            this.lblProductionLine.AccessibleDescription = null;
            this.lblProductionLine.AccessibleName = null;
            resources.ApplyResources(this.lblProductionLine, "lblProductionLine");
            this.lblProductionLine.Font = null;
            this.lblProductionLine.ForeColor = System.Drawing.Color.Maroon;
            this.lblProductionLine.Name = "lblProductionLine";
            this.lblProductionLine.Tag = "0";
            // 
            // btnProductionLine
            // 
            this.btnProductionLine.AccessibleDescription = null;
            this.btnProductionLine.AccessibleName = null;
            resources.ApplyResources(this.btnProductionLine, "btnProductionLine");
            this.btnProductionLine.BackgroundImage = null;
            this.btnProductionLine.Font = null;
            this.btnProductionLine.Name = "btnProductionLine";
            this.btnProductionLine.Click += new System.EventHandler(this.btnProductionLine_Click);
            // 
            // btnworkcenter
            // 
            this.btnworkcenter.AccessibleDescription = null;
            this.btnworkcenter.AccessibleName = null;
            resources.ApplyResources(this.btnworkcenter, "btnworkcenter");
            this.btnworkcenter.BackgroundImage = null;
            this.btnworkcenter.Font = null;
            this.btnworkcenter.Name = "btnworkcenter";
            this.btnworkcenter.Click += new System.EventHandler(this.btnworkcenter_Click);
            // 
            // txtWorkcenter
            // 
            this.txtWorkcenter.AccessibleDescription = null;
            this.txtWorkcenter.AccessibleName = null;
            resources.ApplyResources(this.txtWorkcenter, "txtWorkcenter");
            this.txtWorkcenter.BackgroundImage = null;
            this.txtWorkcenter.Font = null;
            this.txtWorkcenter.Name = "txtWorkcenter";
            this.txtWorkcenter.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtWorkcenter_KeyDown);
            this.txtWorkcenter.Validating += new System.ComponentModel.CancelEventHandler(this.txtWorkcenter_Validating);
            // 
            // lblWorkCenter
            // 
            this.lblWorkCenter.AccessibleDescription = null;
            this.lblWorkCenter.AccessibleName = null;
            resources.ApplyResources(this.lblWorkCenter, "lblWorkCenter");
            this.lblWorkCenter.Font = null;
            this.lblWorkCenter.ForeColor = System.Drawing.Color.Maroon;
            this.lblWorkCenter.Name = "lblWorkCenter";
            // 
            // btnClose
            // 
            this.btnClose.AccessibleDescription = null;
            this.btnClose.AccessibleName = null;
            resources.ApplyResources(this.btnClose, "btnClose");
            this.btnClose.BackgroundImage = null;
            this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnClose.Font = null;
            this.btnClose.Name = "btnClose";
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // btnHelp
            // 
            this.btnHelp.AccessibleDescription = null;
            this.btnHelp.AccessibleName = null;
            resources.ApplyResources(this.btnHelp, "btnHelp");
            this.btnHelp.BackgroundImage = null;
            this.btnHelp.Font = null;
            this.btnHelp.Name = "btnHelp";
            // 
            // btnSave
            // 
            this.btnSave.AccessibleDescription = null;
            this.btnSave.AccessibleName = null;
            resources.ApplyResources(this.btnSave, "btnSave");
            this.btnSave.BackgroundImage = null;
            this.btnSave.Font = null;
            this.btnSave.Name = "btnSave";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // chkSelectAll
            // 
            this.chkSelectAll.AccessibleDescription = null;
            this.chkSelectAll.AccessibleName = null;
            resources.ApplyResources(this.chkSelectAll, "chkSelectAll");
            this.chkSelectAll.BackgroundImage = null;
            this.chkSelectAll.Font = null;
            this.chkSelectAll.Name = "chkSelectAll";
            this.chkSelectAll.Leave += new System.EventHandler(this.chkSelectAll_Leave);
            this.chkSelectAll.Enter += new System.EventHandler(this.chkSelectAll_Enter);
            this.chkSelectAll.CheckedChanged += new System.EventHandler(this.chkSelectAll_CheckedChanged);
            // 
            // btnPrintBOMShortage
            // 
            this.btnPrintBOMShortage.AccessibleDescription = null;
            this.btnPrintBOMShortage.AccessibleName = null;
            resources.ApplyResources(this.btnPrintBOMShortage, "btnPrintBOMShortage");
            this.btnPrintBOMShortage.BackgroundImage = null;
            this.btnPrintBOMShortage.Font = null;
            this.btnPrintBOMShortage.Name = "btnPrintBOMShortage";
            this.btnPrintBOMShortage.Click += new System.EventHandler(this.btnPrintBOMShortage_Click);
            // 
            // lblLocation
            // 
            this.lblLocation.AccessibleDescription = null;
            this.lblLocation.AccessibleName = null;
            resources.ApplyResources(this.lblLocation, "lblLocation");
            this.lblLocation.ForeColor = System.Drawing.Color.Maroon;
            this.lblLocation.Name = "lblLocation";
            // 
            // txtLocation
            // 
            this.txtLocation.AccessibleDescription = null;
            this.txtLocation.AccessibleName = null;
            resources.ApplyResources(this.txtLocation, "txtLocation");
            this.txtLocation.BackgroundImage = null;
            this.txtLocation.Font = null;
            this.txtLocation.Name = "txtLocation";
            this.txtLocation.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLocation_KeyDown);
            this.txtLocation.Validating += new System.ComponentModel.CancelEventHandler(this.txtLocation_Validating);
            // 
            // btnSearchLocation
            // 
            this.btnSearchLocation.AccessibleDescription = null;
            this.btnSearchLocation.AccessibleName = null;
            resources.ApplyResources(this.btnSearchLocation, "btnSearchLocation");
            this.btnSearchLocation.BackgroundImage = null;
            this.btnSearchLocation.Font = null;
            this.btnSearchLocation.Name = "btnSearchLocation";
            this.btnSearchLocation.Click += new System.EventHandler(this.btnSearchLocation_Click);
            // 
            // dgrdData
            // 
            this.dgrdData.AccessibleDescription = null;
            this.dgrdData.AccessibleName = null;
            resources.ApplyResources(this.dgrdData, "dgrdData");
            this.dgrdData.BackgroundImage = null;
            this.dgrdData.CaptionStyle = style1;
            this.dgrdData.ChildGrid = null;
            this.dgrdData.EditorStyle = style2;
            this.dgrdData.EvenRowStyle = style3;
            this.dgrdData.FilterBarStyle = style4;
            this.dgrdData.Font = null;
            this.dgrdData.FooterStyle = style5;
            this.dgrdData.GroupStyle = style6;
            this.dgrdData.HeadingStyle = style7;
            this.dgrdData.HighLightRowStyle = style8;
            this.dgrdData.Images.Add(((System.Drawing.Image)(resources.GetObject("dgrdData.Images"))));
            this.dgrdData.InactiveStyle = style9;
            this.dgrdData.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.DottedCellBorder;
            this.dgrdData.Name = "dgrdData";
            this.dgrdData.OddRowStyle = style10;
            this.dgrdData.PictureAddnewRow = null;
            this.dgrdData.PictureCurrentRow = null;
            this.dgrdData.PictureFilterBar = null;
            this.dgrdData.PictureFooterRow = null;
            this.dgrdData.PictureHeaderRow = null;
            this.dgrdData.PictureModifiedRow = null;
            this.dgrdData.PictureStandardRow = null;
            this.dgrdData.PreviewInfo.AllowSizing = ((bool)(resources.GetObject("dgrdData.PreviewInfo.AllowSizing")));
            this.dgrdData.PreviewInfo.Caption = resources.GetString("dgrdData.PreviewInfo.Caption");
            this.dgrdData.PreviewInfo.Location = ((System.Drawing.Point)(resources.GetObject("dgrdData.PreviewInfo.Location")));
            this.dgrdData.PreviewInfo.Size = ((System.Drawing.Size)(resources.GetObject("dgrdData.PreviewInfo.Size")));
            this.dgrdData.PreviewInfo.ToolBars = ((bool)(resources.GetObject("dgrdData.PreviewInfo.ToolBars")));
            this.dgrdData.PreviewInfo.UIStrings.Content = ((string[])(resources.GetObject("dgrdData.PreviewInfo.UIStrings.Content")));
            this.dgrdData.PreviewInfo.ZoomFactor = ((double)(resources.GetObject("dgrdData.PreviewInfo.ZoomFactor")));
            this.dgrdData.PrintInfo.MaxRowHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.MaxRowHeight")));
            this.dgrdData.PrintInfo.OwnerDrawPageFooter = ((bool)(resources.GetObject("dgrdData.PrintInfo.OwnerDrawPageFooter")));
            this.dgrdData.PrintInfo.OwnerDrawPageHeader = ((bool)(resources.GetObject("dgrdData.PrintInfo.OwnerDrawPageHeader")));
            this.dgrdData.PrintInfo.PageFooter = resources.GetString("dgrdData.PrintInfo.PageFooter");
            this.dgrdData.PrintInfo.PageFooterHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.PageFooterHeight")));
            this.dgrdData.PrintInfo.PageHeader = resources.GetString("dgrdData.PrintInfo.PageHeader");
            this.dgrdData.PrintInfo.PageHeaderHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.PageHeaderHeight")));
            this.dgrdData.PrintInfo.PageSettings = ((System.Drawing.Printing.PageSettings)(resources.GetObject("dgrdData.PrintInfo.PageSettings")));
            this.dgrdData.PrintInfo.PrintHorizontalSplits = ((bool)(resources.GetObject("dgrdData.PrintInfo.PrintHorizontalSplits")));
            this.dgrdData.PrintInfo.ProgressCaption = resources.GetString("dgrdData.PrintInfo.ProgressCaption");
            this.dgrdData.PrintInfo.RepeatColumnFooters = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatColumnFooters")));
            this.dgrdData.PrintInfo.RepeatColumnHeaders = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatColumnHeaders")));
            this.dgrdData.PrintInfo.RepeatGridHeader = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatGridHeader")));
            this.dgrdData.PrintInfo.RepeatSplitHeaders = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatSplitHeaders")));
            this.dgrdData.PrintInfo.ShowOptionsDialog = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowOptionsDialog")));
            this.dgrdData.PrintInfo.ShowProgressForm = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowProgressForm")));
            this.dgrdData.PrintInfo.ShowSelection = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowSelection")));
            this.dgrdData.PrintInfo.UseGridColors = ((bool)(resources.GetObject("dgrdData.PrintInfo.UseGridColors")));
            this.dgrdData.RecordSelectorStyle = style11;
            this.dgrdData.RowDivider.Color = ((System.Drawing.Color)(resources.GetObject("resource.Color")));
            this.dgrdData.RowDivider.Style = ((C1.Win.C1TrueDBGrid.LineStyleEnum)(resources.GetObject("resource.Style")));
            this.dgrdData.SelectedStyle = style12;
            this.dgrdData.Style = style13;
            this.dgrdData.ButtonClick += new C1.Win.C1TrueDBGrid.ColEventHandler(this.dgrdData_ButtonClick);
            this.dgrdData.BeforeColUpdate += new C1.Win.C1TrueDBGrid.BeforeColUpdateEventHandler(this.dgrdData_BeforeColUpdate);
            this.dgrdData.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dgrdData_KeyDown);
            this.dgrdData.AfterColUpdate += new C1.Win.C1TrueDBGrid.ColEventHandler(this.dgrdData_AfterColUpdate);
            // 
            // MultiWOCompletion
            // 
            this.AccessibleDescription = null;
            this.AccessibleName = null;
            resources.ApplyResources(this, "$this");
            this.BackgroundImage = null;
            this.CancelButton = this.btnClose;
            this.Controls.Add(this.dgrdData);
            this.Controls.Add(this.txtLocation);
            this.Controls.Add(this.txtWorkcenter);
            this.Controls.Add(this.txtProductionLine);
            this.Controls.Add(this.txtFGoodsCode);
            this.Controls.Add(this.txtMasLoc);
            this.Controls.Add(this.lblLocation);
            this.Controls.Add(this.btnSearchLocation);
            this.Controls.Add(this.btnPrintBOMShortage);
            this.Controls.Add(this.btnClose);
            this.Controls.Add(this.btnHelp);
            this.Controls.Add(this.btnSave);
            this.Controls.Add(this.chkSelectAll);
            this.Controls.Add(this.btnworkcenter);
            this.Controls.Add(this.lblWorkCenter);
            this.Controls.Add(this.lblProductionLine);
            this.Controls.Add(this.btnProductionLine);
            this.Controls.Add(this.lblFGoodsCode);
            this.Controls.Add(this.btnFGoodsCode);
            this.Controls.Add(this.dtmPostDate);
            this.Controls.Add(this.btnSearchMasLoc);
            this.Controls.Add(this.lblMasLoc);
            this.Controls.Add(this.lblPostDate);
            this.Font = null;
            this.Icon = null;
            this.Name = "MultiWOCompletion";
            this.Load += new System.EventHandler(this.MultiWOCompletion_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dtmPostDate)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgrdData)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        private void FillGridData()
        {
            int intSaleOrderDetailID = Convert.ToInt32(txtFGoodsCode.Tag);
            int intProductionLineID = Convert.ToInt32(txtProductionLine.Tag);
            int intWorkCenterID = Convert.ToInt32(txtWorkcenter.Tag);
            int intLocationID = Convert.ToInt32(txtLocation.Tag);
            dstData = boWOCompletion.SearchForMultiCompletion(intSaleOrderDetailID, intProductionLineID, intWorkCenterID, intLocationID);

            dgrdData.DataSource = dstData.Tables[0];
            FormControlComponents.RestoreGridLayout(dgrdData, dtbGridLayout);

            foreach (C1DisplayColumn c1Col in dgrdData.Splits[0].DisplayColumns)
            {
                c1Col.Locked = true;
                c1Col.Button = false;
            }

            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD].Locked = false;
            dgrdData.Splits[0].DisplayColumns[Constants.SELECTED_STR].Locked = false;
            dgrdData.Splits[0].DisplayColumns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].Locked = false;
            dgrdData.Splits[0].DisplayColumns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].Button = true;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD].DataColumn.NumberFormat = Constants.INTERGER_NUMBERFORMAT;
            dgrdData.Splits[0].DisplayColumns[PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD].DataColumn.NumberFormat = Constants.INTERGER_NUMBERFORMAT;
            dgrdData.Splits[0].DisplayColumns[PRO_RequiredMaterialDetailTable.QUANTITY_FLD].DataColumn.NumberFormat = Constants.INTERGER_NUMBERFORMAT;
        }
        private bool ValidateData()
        {
            //Check Mandatory
            if (FormControlComponents.CheckMandatory(dtmPostDate))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                dtmPostDate.Focus();
                dtmPostDate.Select();
                return false;
            }

            //Check date in period
            if (!FormControlComponents.CheckDateInCurrentPeriod(DateTime.Parse(dtmPostDate.Value.ToString())))
            {
                PCSMessageBox.Show(ErrorCode.MESSAGE_RGV_POSTDATE_PERIOD, MessageBoxIcon.Exclamation);
                dtmPostDate.Focus();
                dtmPostDate.Select();
                return false;
            }
            //check the PostDate smaller than the current date
            if ((DateTime)dtmPostDate.Value > new UtilsBO().GetDBDate())
            {
                //MessageBox.Show("The Post Date you input is not in the current period");
                PCSMessageBox.Show(ErrorCode.MESSAGE_INV_TRANSACTION_CANNOT_IN_FUTURE, MessageBoxIcon.Warning);
                dtmPostDate.Focus();
                return false;
            }
            if (FormControlComponents.CheckMandatory(txtFGoodsCode))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                txtFGoodsCode.Focus();
                txtFGoodsCode.Select();
                return false;
            }
            if (FormControlComponents.CheckMandatory(txtProductionLine))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                txtProductionLine.Focus();
                txtProductionLine.Select();
                return false;
            }
            if (FormControlComponents.CheckMandatory(txtWorkcenter))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                txtWorkcenter.Focus();
                txtWorkcenter.Select();
                return false;
            }
            if (FormControlComponents.CheckMandatory(txtMasLoc))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                txtMasLoc.Focus();
                txtMasLoc.Select();
                return false;
            }
            if (FormControlComponents.CheckMandatory(txtLocation))
            {
                PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                txtLocation.Focus();
                txtLocation.Select();
                return false;
            }
            for (int i = 0; i < dgrdData.RowCount; i++)
            {
                if (Convert.ToBoolean(dgrdData[i, Constants.SELECTED_STR]))
                {
                    #region check completed quantity

                    try
                    {
                        decimal decCompletedQty = Convert.ToDecimal(dgrdData[i, PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD]);
                        if (decCompletedQty <= 0)
                        {
                            PCSMessageBox.Show(ErrorCode.MESSAGE_WOCOMPLETION_COMPQTY_MUST_BE_GREATER_ZERO, MessageBoxIcon.Warning);
                            dgrdData.Row = i;
                            dgrdData.Col = dgrdData.Columns.IndexOf(dgrdData.Columns[PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD]);
                            return false;
                        }
                        // checking total completion quantity cannot exceed order quantity
                        decimal decOrderQuantity = Convert.ToDecimal(dgrdData[i, PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD]);
                        decimal decTotalCompletedQuantity = decCompletedQty;
                        int intWorkOrderMasterID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderDetailTable.WORKORDERMASTERID_FLD]);
                        int intWorkOrderDetailID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD]);
                        try
                        {
                            decTotalCompletedQuantity = decCompletedQty + boWOCompletion.GetCompletedQuantity(intWorkOrderMasterID, intWorkOrderDetailID);
                        }
                        catch { }
                        if (decOrderQuantity < decTotalCompletedQuantity)
                        {
                            PCSMessageBox.Show(ErrorCode.MESSAGE_COMPLETION_OVER_ORDER, MessageBoxIcon.Exclamation);
                            dgrdData.Row = i;
                            dgrdData.Col = dgrdData.Columns.IndexOf(dgrdData.Columns[PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD]);
                            return false;
                        }
                    }
                    catch
                    {
                        PCSMessageBox.Show(ErrorCode.MESSAGE_INVALID_NUMERIC, MessageBoxIcon.Warning);
                        dgrdData.Row = i;
                        dgrdData.Col = dgrdData.Columns.IndexOf(dgrdData.Columns[PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD]);
                        return false;
                    }

                    #endregion

                    #region check bin
                    if (dgrdData[i, PRO_WorkOrderCompletionTable.BINID_FLD] == null ||
                        dgrdData[i, MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].ToString() == string.Empty)
                    {
                        PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Exclamation);
                        dgrdData.Row = i;
                        dgrdData.Col = dgrdData.Columns.IndexOf(dgrdData.Columns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD]);
                        return false;
                    }
                    #endregion
                }
            }
            return true;
        }
        private void ShowBOMShortageReport(object sender, System.EventArgs e)
        {
            const string APPLICATION_PATH = @"PCSMain\bin\Debug";
            const string RPT_COMPANY_FIELD = "fldCompany";
            const string RPT_COMPLETED_QUANTITY_FIELD = "fldCompletedQuantity";

            const string BOM_SHORTAGE_REPORT = "BOMShortageReport.xml";
            try
            {
                //return if no record was selected
                if (dgrdData.Row < 0)
                    return;

                //Change cursor type
                this.Cursor = Cursors.WaitCursor;

                DataRow[] drows=new DataRow[1000000];
                string strFillter = " Selected=True";
                int iBinID = 0;
                if (dstData != null && dstData.Tables.Count > 0)
                {
                    drows = dstData.Tables[0].Select(strFillter);
                    
                }
                string strProductID = "";
                string strWorkOrderDetailID = "";
                int iSaleOrderDetailID=0;
                if (txtFGoodsCode.Tag != null)
                {
                    iSaleOrderDetailID = Convert.ToInt32(txtFGoodsCode.Tag);
                }
                string strPhay = ",";
                int idem = 0;
                if (drows != null && drows.Length > 0)
                {
                    foreach (DataRow dr in drows)
                    {
                        if (idem > 0 && idem < drows.Length)
                        {
                            strProductID += strPhay + dr["ProductID"].ToString();
                            strWorkOrderDetailID += strPhay + dr["WorkOrderDetailID"].ToString();
                            iBinID = Convert.ToInt32(dr[MST_BINTable.BINID_FLD]);
                        }
                        else
                        {
                            strProductID += dr["ProductID"].ToString();
                            strWorkOrderDetailID +=dr["WorkOrderDetailID"].ToString();
                            iBinID = Convert.ToInt32(dr[MST_BINTable.BINID_FLD]);
                        }
                        idem++;
                    }
                }
                else
                {
                    return;
                }
                //get completed quatity
                decimal decCompletedQuantity = decimal.Zero;
                try
                {
                    decCompletedQuantity = Convert.ToDecimal(dgrdData[intSelectedRow, PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD]);
                }
                catch { }

                C1PrintPreviewDialog printPreview = new C1PrintPreviewDialog();
                C1PrintPreviewDialogBO boDataReport = new C1PrintPreviewDialogBO();

                DataTable dtbResult;
                //dtbResult = boDataReport.GetWOBOMShortageData(Convert.ToInt32(dgrdData[intSelectedRow, PRO_WorkOrderCompletionTable.WORKORDERDETAILID_FLD]), decCompletedQuantity);
                dtbResult = boDataReport.GetListBOM(iBinID, iSaleOrderDetailID, strWorkOrderDetailID, strProductID);
                // Check data source
                if (dtbResult == null)
                {
                    this.Cursor = Cursors.Default;
                    return;
                }

                ReportBuilder reportBuilder = new ReportBuilder();

                //Get actual application path
                string strReportPath = Application.StartupPath;
                int intIndex = strReportPath.IndexOf(APPLICATION_PATH);
                if (intIndex > -1)
                {
                    strReportPath = strReportPath.Substring(0, intIndex);
                }

                if (strReportPath.Substring(strReportPath.Length - 1) == @"\")
                {
                    strReportPath += Constants.REPORT_DEFINITION_STORE_LOCATION;
                }
                else
                {
                    strReportPath += @"\" + Constants.REPORT_DEFINITION_STORE_LOCATION;
                }

                //Set datasource and lay-out path for reports
                reportBuilder.SourceDataTable = dtbResult;
                reportBuilder.ReportDefinitionFolder = strReportPath;

                reportBuilder.ReportLayoutFile = BOM_SHORTAGE_REPORT;

                //check if layout is valid
                if (reportBuilder.AnalyseLayoutFile())
                {
                    reportBuilder.UseLayoutFile = true;
                }
                else
                {
                    this.Cursor = Cursors.Default;
                    PCSMessageBox.Show(ErrorCode.MESSAGE_REPORT_TEMPLATE_FILE_NOT_FOUND, MessageBoxIcon.Error);
                    return;
                }

                reportBuilder.MakeDataTableForRender();

                // and show it in preview dialog								
                reportBuilder.ReportViewer = printPreview.ReportViewer;
                reportBuilder.RenderReport();

                //Header information get from system params				
                reportBuilder.DrawPredefinedField(RPT_COMPANY_FIELD, SystemProperty.SytemParams.Get(SystemParam.COMPANY_FULL_NAME));
                reportBuilder.DrawPredefinedField(RPT_COMPLETED_QUANTITY_FIELD, decCompletedQuantity.ToString(Constants.DECIMAL_NUMBERFORMAT));

                reportBuilder.RefreshReport();

                //Print report
                try
                {
                    printPreview.FormTitle = reportBuilder.GetFieldByName("fldTitle").Text;
                }
                catch { }
                printPreview.Show();
            }
            catch
            {

            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void MultiWOCompletion_Load(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".MultiWOCompletion_Load()";
            try
            {
                //Set authorization for user
                Security objSecurity = new Security();
                this.Name = THIS;
                if (objSecurity.SetRightForUserOnForm(this, SystemProperty.UserName) == 0)
                {
                    this.Close();
                    // You don't have the right to view this item
                    PCSMessageBox.Show(ErrorCode.MESSAGE_YOU_HAVE_NO_RIGHT_TO_VIEW, MessageBoxIcon.Warning);
                    return;
                }

                FormControlComponents.SetDefaultMasterLocation(txtMasLoc);
                dtmPostDate.Value = new UtilsBO().GetDBDate();
                dtmPostDate.FormatType = FormatTypeEnum.CustomFormat;
                dtmPostDate.CustomFormat = Constants.DATETIME_FORMAT_HOUR;

                dtbGridLayout = FormControlComponents.StoreGridLayout(dgrdData);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }
        private void txtMasLoc_Validating(object sender, CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtMasLoc_Validating()";
            try
            {
                if (txtMasLoc.Modified)
                {
                    if (txtMasLoc.Text.Trim().Length == 0)
                    {
                        txtMasLoc.Tag = null;
                        txtLocation.Text = string.Empty;
                        txtLocation.Tag = null;
                        // clear grid
                        if (dstData != null && dstData.Tables.Count > 0)
                            dstData.Tables[0].Clear();
                        return;
                    }

                    DataRowView drwResult = null;

                    drwResult = FormControlComponents.OpenSearchForm(MST_MasterLocationTable.TABLE_NAME, MST_MasterLocationTable.CODE_FLD, txtMasLoc.Text, null, false);
                    if (drwResult != null)
                    {
                        txtMasLoc.Text = drwResult[MST_MasterLocationTable.CODE_FLD].ToString();
                        int intMasterLocationID = Convert.ToInt32(drwResult[MST_MasterLocationTable.MASTERLOCATIONID_FLD]);
                        if (txtMasLoc.Tag == null || !txtMasLoc.Tag.Equals(intMasterLocationID))
                        {
                            txtLocation.Text = string.Empty;
                            txtLocation.Tag = null;
                            // clear grid
                            if (dstData != null && dstData.Tables.Count > 0)
                                dstData.Tables[0].Clear();
                        }
                    }
                    else
                        e.Cancel = true;
                }
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtMasLoc_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtMasLoc_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F4)
                    btnSearchMasLoc_Click(null, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void btnSearchMasLoc_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSearchMasLoc_Click()";
            try
            {
                DataRowView drwResult = null;

                drwResult = FormControlComponents.OpenSearchForm(MST_MasterLocationTable.TABLE_NAME, MST_MasterLocationTable.CODE_FLD, txtMasLoc.Text, null, true);
                if (drwResult != null)
                {
                    txtMasLoc.Text = drwResult[MST_MasterLocationTable.CODE_FLD].ToString();
                    int intMasterLocationID = Convert.ToInt32(drwResult[MST_MasterLocationTable.MASTERLOCATIONID_FLD]);
                    if (txtMasLoc.Tag == null || !txtMasLoc.Tag.Equals(intMasterLocationID))
                    {
                        txtLocation.Text = string.Empty;
                        txtLocation.Tag = null;
                        // clear grid
                        if (dstData != null && dstData.Tables.Count > 0)
                            dstData.Tables[0].Clear();
                    }
                }
                else
                    txtMasLoc.Focus();
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtFGoodsCode_Validating(object sender, CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtFGoodsCode_Validating()";
            try
            {
                if (!txtFGoodsCode.Modified)
                    return;
                if (txtFGoodsCode.Text.Trim() == string.Empty)
                {
                    txtFGoodsCode.Tag = null;
                    if (dstData.Tables.Count > 0)
                        dstData.Tables[0].Clear();
                    return;
                }
                DataRowView drwResult = null;
                drwResult = FormControlComponents.OpenSearchForm(SO_SaleOrderDetailTable.TABLE_NAME, SO_SaleOrderDetailTable.FGOODSCODE_FLD, txtFGoodsCode.Text, null, false);
                if (drwResult != null)
                {
                    txtFGoodsCode.Tag = Convert.ToInt32(drwResult[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD]);
                    txtFGoodsCode.Text = drwResult[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                    if (txtWorkcenter.Tag != null)
                        FillGridData();
                    else
                    {
                        if (dstData.Tables.Count > 0)
                            dstData.Tables[0].Clear();
                    }
                }
                else
                    e.Cancel = true;
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtFGoodsCode_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtFGoodsCode_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F4)
                    btnFGoodsCode_Click(null, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void btnFGoodsCode_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnFGoodsCode_Click()";
            try
            {
                DataRowView drwResult = null;
                drwResult = FormControlComponents.OpenSearchForm(SO_SaleOrderDetailTable.TABLE_NAME, SO_SaleOrderDetailTable.FGOODSCODE_FLD, txtFGoodsCode.Text, null, true);
                if (drwResult != null)
                {
                    txtFGoodsCode.Tag = Convert.ToInt32(drwResult[SO_SaleOrderDetailTable.SALEORDERDETAILID_FLD]);
                    txtFGoodsCode.Text = drwResult[SO_SaleOrderDetailTable.FGOODSCODE_FLD].ToString();
                    if (txtWorkcenter.Tag != null)
                        FillGridData();
                    else
                    {
                        if (dstData.Tables.Count > 0)
                            dstData.Tables[0].Clear();
                    }
                }
                else
                    txtFGoodsCode.Focus();
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtProductionLine_Validating(object sender, CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtProductionLine_Validating()";
            try
            {
                if (!txtProductionLine.Modified)
                    return;
                if (txtProductionLine.Text.Trim() == string.Empty)
                {
                    txtProductionLine.Tag = null;
                    txtWorkcenter.Text = string.Empty;
                    txtWorkcenter.Tag = null;
                    if (dstData.Tables.Count > 0)
                        dstData.Tables[0].Rows.Clear();
                    return;
                }
                DataRowView drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, txtProductionLine.Text.Trim(), null, false);

                if (drwResult != null)
                {
                    if (txtProductionLine.Text.Trim() == string.Empty || txtProductionLine.Text.Trim() != drwResult[PRO_ProductionLineTable.CODE_FLD].ToString().Trim())
                    {
                        if (dstData.Tables.Count > 0)
                            dstData.Tables[0].Rows.Clear();
                        txtWorkcenter.Tag = null;
                        txtWorkcenter.Text = string.Empty;

                        #region fill default location

                        try
                        {
                            int intLocationID = Convert.ToInt32(drwResult[PRO_ProductionLineTable.LOCATIONID_FLD]);
                            txtLocation.Tag = intLocationID;
                            txtLocation.Text = FormControlComponents.OpenSearchForm(MST_LocationTable.TABLE_NAME, MST_LocationTable.LOCATIONID_FLD, intLocationID.ToString(), null, false)[MST_LocationTable.CODE_FLD].ToString();
                        }
                        catch { }

                        #endregion
                    }
                    txtProductionLine.Text = drwResult[PRO_ProductionLineTable.CODE_FLD].ToString();
                    txtProductionLine.Tag = int.Parse(drwResult[PRO_ProductionLineTable.PRODUCTIONLINEID_FLD].ToString());
                }
                else
                    e.Cancel = true;
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtProductionLine_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtProductionLine_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F4)
                    btnProductionLine_Click(null, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void btnProductionLine_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnProductionLine_Click()";
            try
            {
                DataRowView drwResult = FormControlComponents.OpenSearchForm(PRO_ProductionLineTable.TABLE_NAME, PRO_ProductionLineTable.CODE_FLD, txtProductionLine.Text.Trim(), null, true);

                if (drwResult != null)
                {
                    if (txtProductionLine.Text.Trim() == string.Empty || txtProductionLine.Text.Trim() != drwResult[PRO_ProductionLineTable.CODE_FLD].ToString().Trim())
                    {
                        if (dstData.Tables.Count > 0)
                            dstData.Tables[0].Rows.Clear();
                        txtWorkcenter.Tag = null;
                        txtWorkcenter.Text = string.Empty;

                        #region fill default location

                        try
                        {
                            int intLocationID = Convert.ToInt32(drwResult[PRO_ProductionLineTable.LOCATIONID_FLD]);
                            txtLocation.Tag = intLocationID;
                            txtLocation.Text = FormControlComponents.OpenSearchForm(MST_LocationTable.TABLE_NAME, MST_LocationTable.LOCATIONID_FLD, intLocationID.ToString(), null, false)[MST_LocationTable.CODE_FLD].ToString();
                        }
                        catch { }

                        #endregion
                    }
                    txtProductionLine.Text = drwResult[PRO_ProductionLineTable.CODE_FLD].ToString();
                    txtProductionLine.Tag = int.Parse(drwResult[PRO_ProductionLineTable.PRODUCTIONLINEID_FLD].ToString());
                }
                else
                    txtProductionLine.Focus();
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtWorkcenter_Validating(object sender, CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtWorkcenter_Validating()";
            try
            {
                if (!txtWorkcenter.Modified)
                    return;
                if (txtWorkcenter.Text.Trim() == string.Empty)
                {
                    txtWorkcenter.Tag = null;
                    txtWorkcenter.Text = string.Empty;
                    if (dstData.Tables.Count > 0)
                        dstData.Tables[0].Rows.Clear();
                    return;
                }
                if (txtProductionLine.Tag == null)
                {
                    string[] strMsg = new string[2] { lblProductionLine.Text, lblWorkCenter.Text };
                    PCSMessageBox.Show(ErrorCode.MESSAGE_SELECT_ONE_BEFORE_SELECT_ONE, MessageBoxIcon.Warning, strMsg);
                    txtWorkcenter.Text = string.Empty;
                    txtProductionLine.Focus();
                    return;
                }
                Hashtable htCondition = new Hashtable();
                htCondition.Add(MST_WorkCenterTable.PRODUCTIONLINEID_FLD, txtProductionLine.Tag);
                DataRowView drwResult = FormControlComponents.OpenSearchForm(MST_WorkCenterTable.TABLE_NAME, MST_WorkCenterTable.CODE_FLD, txtWorkcenter.Text.Trim(), htCondition, false);

                if (drwResult != null)
                {
                    if (txtWorkcenter.Text.Trim() == string.Empty || txtWorkcenter.Text.Trim() != drwResult[MST_WorkCenterTable.CODE_FLD].ToString().Trim())
                        txtWorkcenter.Tag = int.Parse(drwResult[MST_WorkCenterTable.WORKCENTERID_FLD].ToString());
                    FillGridData();
                    txtWorkcenter.Text = drwResult[MST_WorkCenterTable.CODE_FLD].ToString();
                }
                else
                    e.Cancel = true;
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtWorkcenter_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtWorkcenter_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F4)
                    btnworkcenter_Click(null, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void btnworkcenter_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnworkcenter_Click()";
            try
            {
                if (txtProductionLine.Tag == null)
                {
                    string[] strMsg = new string[2] { lblProductionLine.Text, lblWorkCenter.Text };
                    PCSMessageBox.Show(ErrorCode.MESSAGE_SELECT_ONE_BEFORE_SELECT_ONE, MessageBoxIcon.Warning, strMsg);
                    txtWorkcenter.Text = string.Empty;
                    txtProductionLine.Focus();
                    return;
                }
                Hashtable htCondition = new Hashtable();
                htCondition.Add(MST_WorkCenterTable.PRODUCTIONLINEID_FLD, txtProductionLine.Tag);
                DataRowView drwResult = FormControlComponents.OpenSearchForm(MST_WorkCenterTable.TABLE_NAME, MST_WorkCenterTable.CODE_FLD, txtWorkcenter.Text.Trim(), htCondition, true);

                if (drwResult != null)
                {
                    if (txtWorkcenter.Text.Trim() == string.Empty || txtWorkcenter.Text.Trim() != drwResult[MST_WorkCenterTable.CODE_FLD].ToString().Trim())
                        txtWorkcenter.Tag = int.Parse(drwResult[MST_WorkCenterTable.WORKCENTERID_FLD].ToString());
                    FillGridData();
                    txtWorkcenter.Text = drwResult[MST_WorkCenterTable.CODE_FLD].ToString();
                }
                else
                    txtWorkcenter.Focus();
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtLocation_Validating(object sender, CancelEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtLocation_Validating()";
            try
            {
                if (!txtLocation.Modified)
                    return;
                if (txtLocation.Text.Trim() == string.Empty)
                {
                    txtLocation.Tag = null;
                    txtLocation.Text = string.Empty;
                    if (dstData.Tables.Count > 0)
                    {
                        // clear all bin in grid
                        for (int i = 0; i < dgrdData.RowCount; i++)
                        {
                            dgrdData[i, PRO_WorkOrderCompletionTable.BINID_FLD] = null;
                            dgrdData[i, MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD] = string.Empty;
                        }
                    }
                    return;
                }
                if (txtMasLoc.Tag == null)
                {
                    string[] strMsg = new string[2] { lblMasLoc.Text, lblLocation.Text };
                    PCSMessageBox.Show(ErrorCode.MESSAGE_SELECT_ONE_BEFORE_SELECT_ONE, MessageBoxIcon.Warning, strMsg);
                    txtLocation.Text = string.Empty;
                    txtMasLoc.Focus();
                    return;
                }
                Hashtable htCondition = new Hashtable();
                htCondition.Add(MST_LocationTable.MASTERLOCATIONID_FLD, txtMasLoc.Tag);
                DataRowView drwResult = FormControlComponents.OpenSearchForm(MST_LocationTable.TABLE_NAME, MST_LocationTable.CODE_FLD, txtLocation.Text.Trim(), htCondition, false);

                if (drwResult != null)
                {
                    if (txtLocation.Text.Trim() == string.Empty || txtLocation.Text.Trim() != drwResult[MST_LocationTable.CODE_FLD].ToString().Trim())
                    {
                        DataRow drowBuffBin = boWOCompletion.GetBuffBin(int.Parse(drwResult[MST_LocationTable.LOCATIONID_FLD].ToString()));
                        // fill default buffer bin of this location to grid
                        for (int i = 0; i < dgrdData.RowCount; i++)
                        {
                            dgrdData[i, PRO_WorkOrderCompletionTable.BINID_FLD] = drowBuffBin[MST_BINTable.BINID_FLD];
                            dgrdData[i, MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD] = drowBuffBin[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD];
                        }
                    }
                    txtLocation.Text = drwResult[MST_LocationTable.CODE_FLD].ToString();

                }
                else
                    e.Cancel = true;
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void txtLocation_KeyDown(object sender, KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".txtLocation_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F4)
                    btnSearchLocation_Click(null, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void btnSearchLocation_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSearchLocation_Click()";
            try
            {
                if (txtMasLoc.Tag == null)
                {
                    string[] strMsg = new string[2] { lblMasLoc.Text, lblLocation.Text };
                    PCSMessageBox.Show(ErrorCode.MESSAGE_SELECT_ONE_BEFORE_SELECT_ONE, MessageBoxIcon.Warning, strMsg);
                    txtLocation.Text = string.Empty;
                    txtMasLoc.Focus();
                    return;
                }
                Hashtable htCondition = new Hashtable();
                htCondition.Add(MST_LocationTable.MASTERLOCATIONID_FLD, txtMasLoc.Tag);
                DataRowView drwResult = FormControlComponents.OpenSearchForm(MST_LocationTable.TABLE_NAME, MST_LocationTable.CODE_FLD, txtLocation.Text.Trim(), htCondition, true);

                if (drwResult != null)
                {
                    if (txtLocation.Text.Trim() == string.Empty || txtLocation.Text.Trim() != drwResult[MST_LocationTable.CODE_FLD].ToString().Trim())
                    {
                        DataRow drowBuffBin = boWOCompletion.GetBuffBin(int.Parse(drwResult[MST_LocationTable.LOCATIONID_FLD].ToString()));
                        // fill default buffer bin of this location to grid
                        for (int i = 0; i < dgrdData.RowCount; i++)
                        {
                            dgrdData[i, PRO_WorkOrderCompletionTable.BINID_FLD] = drowBuffBin[MST_BINTable.BINID_FLD];
                            dgrdData[i, MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD] = drowBuffBin[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD];
                        }
                        txtLocation.Tag = int.Parse(drwResult[MST_LocationTable.LOCATIONID_FLD].ToString());
                    }
                    txtLocation.Text = drwResult[MST_LocationTable.CODE_FLD].ToString();
                }
                else
                    txtLocation.Focus();
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void dgrdData_ButtonClick(object sender, ColEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_ButtonClick()";
            try
            {
                if (dgrdData.Columns[dgrdData.Col].DataField == MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD)
                {
                    if (txtLocation.Text.Length == 0)
                    {
                        PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Warning);
                        txtLocation.Focus();
                        return;
                    }
                    Hashtable htbCondition = new Hashtable();
                    htbCondition.Add(MST_BINTable.LOCATIONID_FLD, txtLocation.Tag);
                    DataRowView drwResult = null;
                    if (dgrdData.AddNewMode == AddNewModeEnum.AddNewCurrent)
                        drwResult = FormControlComponents.OpenSearchForm(MST_BINTable.TABLE_NAME, MST_BINTable.CODE_FLD, dgrdData[dgrdData.Row, MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].ToString(), htbCondition, true);
                    else
                        drwResult = FormControlComponents.OpenSearchForm(MST_BINTable.TABLE_NAME, MST_BINTable.CODE_FLD, dgrdData.Columns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].Value.ToString().Trim(), htbCondition, true);
                    if (drwResult != null)
                    {
                        dgrdData.EditActive = true;
                        dgrdData.Columns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].Value = drwResult[MST_BINTable.CODE_FLD];
                        dgrdData.Columns[PRO_WorkOrderCompletionTable.BINID_FLD].Value = drwResult[MST_BINTable.BINID_FLD];
                    }
                }
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void dgrdData_BeforeColUpdate(object sender, C1.Win.C1TrueDBGrid.BeforeColUpdateEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_BeforeUpdate()";
            try
            {
                Hashtable htbCondition = new Hashtable();
                string strColumnName = e.Column.DataColumn.DataField;
                DataRowView drwResult = null;
                switch (strColumnName)
                {
                    case MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD:

                        if (txtLocation.Text.Length == 0)
                        {
                            PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID, MessageBoxIcon.Warning);
                            txtLocation.Focus();
                            return;
                        }
                        htbCondition.Add(MST_BINTable.LOCATIONID_FLD, txtLocation.Tag);

                        if (dgrdData.Columns[e.Column.DataColumn.DataField].Text.Trim() != string.Empty)
                        {
                            drwResult = FormControlComponents.OpenSearchForm(MST_BINTable.TABLE_NAME, MST_BINTable.CODE_FLD, dgrdData.Columns[e.Column.DataColumn.DataField].Value.ToString().Trim(), htbCondition, false);
                            if (drwResult != null)
                                e.Column.DataColumn.Tag = drwResult.Row;
                            else
                                e.Cancel = true;
                        }
                        else
                            e.Column.DataColumn.Tag = null;
                        break;
                    case PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD:
                        decimal decQty = 0;
                        try
                        {
                            decQty = Convert.ToDecimal(e.Column.DataColumn.Value);
                            if (decQty <= 0)
                            {
                                PCSMessageBox.Show(ErrorCode.MESSAGE_WOCOMPLETION_COMPQTY_MUST_BE_GREATER_ZERO, MessageBoxIcon.Warning);
                                e.Cancel = true;
                            }
                        }
                        catch
                        {
                            PCSMessageBox.Show(ErrorCode.MESSAGE_INVALID_NUMERIC, MessageBoxIcon.Warning);
                            e.Cancel = true;
                        }
                        break;
                }
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void dgrdData_AfterColUpdate(object sender, ColEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_AfterColUpdate()";
            try
            {
                DataRow drwResult = (DataRow)e.Column.DataColumn.Tag;
                if (e.Column.DataColumn.DataField == MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD)
                {
                    dgrdData.EditActive = true;
                    if (drwResult != null)
                    {
                        dgrdData.Columns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].Value = drwResult[MST_BINTable.CODE_FLD];
                        dgrdData.Columns[PRO_WorkOrderCompletionTable.BINID_FLD].Value = drwResult[MST_BINTable.BINID_FLD];
                    }
                    else
                    {
                        dgrdData.Columns[MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD].Value = string.Empty;
                        dgrdData.Columns[PRO_WorkOrderCompletionTable.BINID_FLD].Value = null;
                    }
                }
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void dgrdData_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            const string METHOD_NAME = THIS + ".dgrdData_KeyDown()";
            try
            {
                if (e.KeyCode == Keys.F4 && dgrdData.Columns[dgrdData.Col].DataField == MST_BINTable.TABLE_NAME + MST_BINTable.CODE_FLD)
                    dgrdData_ButtonClick(null, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void btnSave_Click(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnSave_Click()";
            try
            {
                if (PCSMessageBox.Show(ErrorCode.MESSAGE_CONFIRM_BEFORE_SAVE_WOCOMPLETION, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, new string[] { dtmPostDate.Text }) == DialogResult.Yes)
                {
                    if (ValidateData())
                    {
                        WorkOrderCompletion frmCompeltion = new WorkOrderCompletion(true);
                        frmCompeltion.Show();
                        Sys_Menu_EntryVO voMenuWOCompletionCK = new UtilsBO().GetMenuInfoForCK(frmCompeltion.Name, PRO_WorkOrderCompletionTable.TABLE_NAME, PRO_WorkOrderCompletionTable.WOCOMPLETIONNO_FLD, "CK");
                        int intProductionLineID = Convert.ToInt32(txtProductionLine.Tag);
                        bool blnHasError = false;
                        for (int i = 0; i < dgrdData.RowCount; i++)
                        {
                            if (Convert.ToBoolean(dgrdData[i, Constants.SELECTED_STR]))
                            {
                                PRO_WorkOrderCompletion voWOCompletion = new PRO_WorkOrderCompletion();
                                voWOCompletion.ShiftID = null;
                                voWOCompletion.IssuePurposeID = (int)PurposeEnum.Completion;
                                voWOCompletion.PostDate = Convert.ToDateTime(dtmPostDate.Value);
                                voWOCompletion.CompletedDate = voWOCompletion.PostDate.Date;
                                voWOCompletion.MasterLocationID = Convert.ToInt32(txtMasLoc.Tag);
                                voWOCompletion.WOCompletionNo = FormControlComponents.GetNoByMask(voMenuWOCompletionCK.TableName, voMenuWOCompletionCK.TransNoFieldName, voMenuWOCompletionCK.Prefix, voMenuWOCompletionCK.TransFormat);
                                voWOCompletion.WorkOrderMasterID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderCompletionTable.WORKORDERMASTERID_FLD]);
                                voWOCompletion.WorkOrderDetailID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderCompletionTable.WORKORDERDETAILID_FLD]);
                                voWOCompletion.ProductID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderCompletionTable.PRODUCTID_FLD]);
                                voWOCompletion.LocationID = int.Parse(txtLocation.Tag.ToString());
                                voWOCompletion.CCNID = 1;
                                voWOCompletion.CompletedQuantity = Convert.ToDecimal(dgrdData[i, PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD]); ;
                                voWOCompletion.StockUMID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderCompletionTable.STOCKUMID_FLD]); ;
                                //Get value of QAStatus combo box
                                voWOCompletion.QAStatus = Convert.ToByte(dgrdData[i, PRO_WorkOrderCompletionTable.QASTATUS_FLD]); ;
                                voWOCompletion.BinID = Convert.ToInt32(dgrdData[i, PRO_WorkOrderCompletionTable.BINID_FLD]);
                                voWOCompletion.UserName = SystemProperty.UserName;

                                decimal decQuantity = Convert.ToDecimal(dgrdData[i, IV_MiscellaneousIssueDetailTable.QUANTITY_FLD]);

                                DateTime dtmServerDate = new UtilsBO().GetDBDate();
                                try
                                {
                                    PRO_WorkOrderCompletionDS dsWOCompletion = new PRO_WorkOrderCompletionDS();
                                    DateTime dt=dtmServerDate.AddDays(1);
                                    DataTable dtbCheckSubtract = dsWOCompletion.GetAvailableQuantityByProductionLinePostDate(dt, intProductionLineID, voWOCompletion.WorkOrderDetailID);
                                    DataTable dtbListOfComponentShortage = new PRO_WOBOMDS().ListComponentByWODetail(voWOCompletion.WorkOrderDetailID);
                                    //boWOCompletion.WorkOrderCompletionForNewBussiness(voWOCompletion, intProductionLineID, decQuantity, dtmServerDate);
                                    boWOCompletion.InsertWorkOrderCompletion(voWOCompletion, intProductionLineID, decQuantity, dtmServerDate, dtbListOfComponentShortage, dtbCheckSubtract);
                                }
                                catch (PCSException ex)
                                {
                                    blnHasError = true;
                                    if (ex.mCode == ErrorCode.MESSAGE_NOT_ENOUGH_COMPONENT_TO_COMPLETE)
                                    {
                                        if (!dtmPostDate.Enabled)
                                        {
                                            if (PCSMessageBox.Show(ex.mCode, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                                            {
                                                intSelectedRow = i;
                                                ShowBOMShortageReport(null, null);
                                            }
                                        }
                                        else
                                        {
                                            string[] strParam = new string[1];
                                            strParam[0] = ex.mMethod;
                                            //Show message
                                            PCSMessageBox.Show(ErrorCode.MESSAGE_NOT_ENOUGH_QUANTITY_OF_COMPONENT_TO_COMPLETE, MessageBoxIcon.Warning, strParam);
                                        }
                                        //End hacked.
                                    }
                                    continue;
                                }
                                catch (Exception ex)
                                {
                                    blnHasError = true;
                                    Logger.LogMessage(ex, METHOD_NAME, Level.DEBUG);
                                    continue;
                                }
                            }
                        }

                        if (!blnHasError)
                            PCSMessageBox.Show(ErrorCode.MESSAGE_AFTER_SAVE_DATA);
                        else
                            PCSMessageBox.Show(ErrorCode.MESSAGE_CANNOT_SAVE_TO_DB);
                        FillGridData();
                    }
                }
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void chkSelectAll_CheckedChanged(object sender, System.EventArgs e)
        {
            const string METHOD_NAME = THIS + ".chkSelectAll_CheckedChanged()";
            try
            {

                if ((blnStateOfCheck) && (dgrdData.RowCount != 0))
                    for (int i = 0; i < dgrdData.RowCount; i++)
                        dgrdData[i, Constants.SELECTED_STR] = chkSelectAll.Checked ? 1 : 0;
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
        }

        private void chkSelectAll_Enter(object sender, System.EventArgs e)
        {
            blnStateOfCheck = true;
        }

        private void chkSelectAll_Leave(object sender, System.EventArgs e)
        {
            blnStateOfCheck = true;
        }

        private void btnClose_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void btnPrintBOMShortage_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = THIS + ".btnPrintBOMShortage_Click()";
            try
            {
                //Change cursor to busy
                this.Cursor = Cursors.WaitCursor;

                //Show report
                ShowBOMShortageReport(this, null);
            }
            catch (PCSException ex)
            {
                // Displays the error message if throwed from PCSException.
                PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // Displays the error message if throwed from system.
                PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
                try
                {
                    // Log error message into log file.
                    Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
                }
                catch
                {
                    // Show message if logger has an error.
                    PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
    }
}
